# Maintainer: Levente Polyak <anthraxx[at]archlinux[dot]org>
# Maintainer: Santiago Torres-Arias <santiago[at]archlinux[dot]org>
# Contributor: spider-mario <spidermario@free.fr>

pkgname=afl
pkgver=2.57b
pkgrel=13
pkgdesc='Security-oriented fuzzer using compile-time instrumentation and genetic algorithms'
url='http://lcamtuf.coredump.cx/afl/'
arch=('loong64' 'x86_64')
license=('Apache')
depends=('glibc' 'bash')
optdepends=('gcc: gcc instrumentation support'
            'clang14: clang instrumentation support'
            'llvm14: experimental clang-fast instrumentation support'
            'gnuplot: graph plotting support')
makedepends=('clang14' 'llvm14' 'gcc' 'wget' 'python' 'lib32-glibc')
provides=('american-fuzzy-lop')
replaces=('american-fuzzy-lop')
options=('!emptydirs' '!strip')
source=(https://github.com/google/AFL/archive/v${pkgver}/${pkgname}-${pkgver}.tar.gz
        llvm13.patch
        llvm14.patch
        clang14.patch)
sha256sums=('6f05a6515c07abe49f6f292bd13c96004cc1e016bda0c3cc9c2769dd43f163ee'
            'ec000fddabc566ac8d2b1af0444843e384d93f7faa4ff55677db1507164ef26f'
            '1f05ba247a295985889669ed892f2150ec38c202c13986fda78f0959e5e39524'
            'b691111bfc326a93725314d849f183b1c22a11597c8a4cd7d54f80cada10a8c3')
sha512sums=('5d12b96229e966aeb11deb47cd8eb36cde2fa32656eb187db02c7240909d6acda36be59b2baf7e42cddd228d25ec94c8bffc3fa27f7f4b5e1e462b62929ce75d'
            '53f1739fe96b24add8b717a5f820ef6b938863c2434e60594bf66fb317808142c369b904d962eac3209128fcf02578b7e0f9908d6e8c53b2a4ebd0fe00ae1cf8'
            '16e12e0e023bc05d00e261a4f06644d8ac07cf8aa18a0781d5316198b1e2829c4d91ad9ec48f3a318ee8bf5a430796c6111a7dbbc3af435a43e495c45d0ae609'
            '25b0b2ac6eb31a77014b56278c1c54f62b7066c0b5caa6d8f0b7aceab9cc81cd746dc40feeb3b758035350ee6c1f3203a12db7a0d5a6c4882d4a2eda02a9d6ba')
b2sums=('69029d59451e468528386154e8938a1a7303765e039f98aa05e36f07314398f60ff2578f765142e1f1ff653e5ab93ea53a2efb98abe275046ebacdd3ca8363b6'
        '60c58a7bd115189a05866899852d760723c6dd255bd684ed90d61c1be56b8bd3bf8702aa9540ad4235469b2dc32253ee645b6f7ac7bbb924eb9f711c3a07e375'
        '0a51146d7e2dcfd18ee7c0d9e730da609b197214a971072262b652e01c0375dd9122c18f97f074b267e49ccfe8c4c22d531e74897cb68daf9c9b6c88722cf3f0'
        '87fd00494897bd86176053e7f6d8d13f4698c61b996ff1cd934b1d4f6c289ca897adc3356eaf31f76e4612a035f8b9e31f0a1f01714967af2ec1cb3f0586928c')

prepare() {
  cd AFL-${pkgver}
  # Minimal build fixes for LLVM 13 and 14 inspired by:
  # https://github.com/AFLplusplus/AFLplusplus/commit/1ba5d1008e74
  # https://github.com/grame-cncm/faust/commit/1275ec6774e0
  patch -Np1 -i ../llvm13.patch
  patch -Np1 -i ../llvm14.patch
  # And let's hope that pointing AFL to the clang14 binaries works
  patch -Np1 -i ../clang14.patch
}

build() {
  cd AFL-${pkgver}
  make PREFIX=/usr
  make -C llvm_mode PREFIX=/usr \
    LLVM_CONFIG=llvm-config-14 CC=/usr/lib/llvm14/bin/clang
}

package() {
  cd AFL-${pkgver}
  make PREFIX=/usr DESTDIR="${pkgdir}" install
  install -Dm 644 llvm_mode/README.llvm -t "${pkgdir}/usr/share/doc/${pkgname}"
}

# vim: ts=2 sw=2 et:
